package com.farmer.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmer.pojo.Information;
import com.farmer.service.InformationService;
import com.farmer.utils.Result;
import com.farmer.utils.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@RestController
@RequestMapping("information")
@CrossOrigin
public class InformationController {

    @Autowired
    private InformationService informationService;


    @PostMapping("add")
    public Result add(@RequestBody Information information) {
      Result result = informationService.add(information);
      return result;
    }
/*
* 单条删除*/
    @DeleteMapping("delete")
    public Result delete(@RequestParam Integer id) {
     Result result = informationService.delete(id);
     return result;
    }
/*
* 批量删除*/
    @DeleteMapping("delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        Result result = informationService.deleteBatch(ids);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Information information) {
        Result result = informationService.update(information);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = informationService.getById(id);
        return result;
    }

    @GetMapping("getAll")
    public Result getAll() {
      Result result = informationService.getAll();
      return result;
    }
    /*
    * 根据标题模糊查询*/
    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String title){
        Result result = informationService.getByTitleLike(title);
        return result;
    }
/*
* 分页查询*/
    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        Result result=informationService.page(pageNum,pageSize);
        return result;
    }

/*
* 显示前六条内容*/
    @GetMapping("show")
    public Result show(){
       Result result = informationService.show();
       return  result;
   }

}
